#include <stdio.h>
#include <string.h>

const int ta=23,tb=28,tc=33;

int tiao(int &a, int &b)
{
	if (a!=b)
	{
		while (a!=b)
		{
			while (a<b) a+=ta;
			while (b<a) b+=tb;
		}
	}
	else
	{
		a+=ta*tb;
		b+=ta*tb;
	}
	return a;
}

main()
{
	int a,b,c,start,d,an,icase=0;
	while (1)
	{
		scanf("%d%d%d%d", &a, &b, &c, &start);
		if (a==-1) break;	
		while (1)
		{			
			d=tiao(a,b);
			if ((d-c)%tc==0) break;			
		}
		an=a-start;
		while (an>21252) an-=21252;		
		if (an<=0) an+=21252;
		printf("Case %d: the next triple peak occurs in %d days.\n",++icase,an);

	}


	return 0;
}